﻿namespace Model.ModelClasses
{
    public class Date : AbstractModel
    {
        private Month _month;
        private int _day;

        public Date(int year, Month month, int day)
        {
            Day = day;
            Month = month;
            Year = year;
        }

        public int Year { get; set; }

        public int Day
        {
            get { return _day; }
            set 
            {
                CheckDate(Month, value);
                _day = value;
            }
        }

        public Month Month
        {
            get { return _month; }
            set
            {
                CheckDate(value, Day);
                _month = value;
            }
        }

        private void CheckDate(Month month, int day)
        {
            switch(month)
            {
                case Month.January: if (day > 31 || day < 1) throw new DateException();
                    break;
                case Month.February: if ((day > 28 && Year % 4 != 0) || (day > 29 && Year % 4 == 0) || day < 0) throw new DateException();
                    break;
                case Month.March: if (day > 31 || day < 1) throw new DateException();
                    break;
                case Month.April: if (day > 30 || day < 1) throw new DateException();
                    break;
                case Month.May: if (day > 31 || day < 1) throw new DateException();
                    break;
                case Month.June: if (day > 30 || day < 1) throw new DateException();
                    break;
                case Month.July: if (day > 31 || day < 1) throw new DateException();
                    break;
                case Month.August: if (day > 31 || day < 1) throw new DateException();
                    break;
                case Month.September: if (day > 30 || day < 1) throw new DateException();
                    break;
                case Month.October: if (day > 31 || day < 1) throw new DateException();
                    break;
                case Month.November: if (day > 30 || day < 1) throw new DateException();
                    break;
                case Month.December: if (day > 31 || day < 1) throw new DateException();
                    break;
                case Month.Unknown:break;
                default: throw new DateException();
            }
        }
    }
}
